package com.springboot.cloud.seckill.dao;

import com.springboot.cloud.seckill.entity.SeckillActivity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.Optional;

/**
 * @author godyao
 * @date 2022/3/26
 */
public interface SeckillRepository extends JpaRepository<SeckillActivity, Long> {
    Optional<SeckillActivity> findByGoodsId(Long goodsId);

    @Query(nativeQuery = true, value = "update t_seckill_activity set stock  = ?2 where goods_id = ?1")
    @Modifying
    int updateStockCount(Long goodsId, Integer stockCount);
}
